//package com.slofzx.nuoda.evaluation.version.service.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.slofzx.nuoda.common.enums.CommonResultEnum;
//import com.slofzx.nuoda.common.enums.ServiceResult;
//import com.slofzx.nuoda.evaluation.version.dto.ComputeVersionDTO;
//import com.slofzx.nuoda.evaluation.version.service.ComputeVersionService;
//import com.slofzx.nuoda.evaluation.enums.ComputeVersionTypeEnum;
//import com.slofzx.nuoda.evaluation.version.service.ComputeVersionStateService;
//import com.slofzx.nuoda.evaluation.project.dao.ProjectInfoDAO;
//import com.slofzx.nuoda.evaluation.project.entity.ProjectInfo;
//import com.slofzx.nuoda.evaluation.project.enums.ProjectStateEnum;
//import com.slofzx.nuoda.evaluation.version.vo.ComputeVersionVO;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import javax.annotation.Resource;
//import java.util.Date;
//
///**
// * 评价信息服务实现类
// *
// * @author nuoda
// * @since 2021-11-19 15:56:06
// */
//@Service
//public class ComputeVersionStateServiceImpl implements ComputeVersionStateService {
//    @Resource
//    private ProjectInfoDAO projectInfoDAO;
//
//    @Autowired
//    protected ComputeVersionService computeVersionService;
//
//    @Transactional
//    @Override
//    public ServiceResult report(ComputeVersionDTO dto) {
//        ComputeVersionVO entity = computeVersionService.queryById(dto.getId());
//        if(entity == null) {
//            return CommonResultEnum.NOT_EXIST;
//        }
//        ProjectInfo projectInfo = projectInfoDAO.selectById(entity.getProjectId());
//        if(projectInfo == null) {
//            return CommonResultEnum.NOT_EXIST;
//        }
//        if(ProjectStateEnum.getEnum(projectInfo.getState())!=ProjectStateEnum.REPORT) {
//            return CommonResultEnum.PERMISSION_DENY;
//        }
//        if(ComputeVersionTypeEnum.getEnum(entity.getType())!=ComputeVersionTypeEnum.DEFAULT) {
//            return CommonResultEnum.PERMISSION_DENY;
//        }
//        ComputeVersionDTO versionDTO = parseVersionVO2DTO(entity);
//        versionDTO.setType(ComputeVersionTypeEnum.REPORT.getId());
//        versionDTO.setReportTime(new Date());
//        computeVersionService.update(versionDTO);
//        projectInfo.setState(ProjectStateEnum.AUDIT.getId());
//        projectInfoDAO.updateById(projectInfo);
//        return CommonResultEnum.SUCCESS;
//    }
//
//    @Transactional
//    @Override
//    public ServiceResult audit(ComputeVersionDTO dto) {
//        ComputeVersionVO entity = computeVersionService.queryById(dto.getId());
//
//        if(entity == null) {
//            return CommonResultEnum.NOT_EXIST;
//        }
//        ProjectInfo projectInfo = projectInfoDAO.selectById(entity.getProjectId());
//        if(projectInfo == null) {
//            return CommonResultEnum.NOT_EXIST;
//        }
//        if(ProjectStateEnum.getEnum(projectInfo.getState())!=ProjectStateEnum.AUDIT) {
//            return CommonResultEnum.PERMISSION_DENY;
//        }
//        if(ComputeVersionTypeEnum.getEnum(entity.getType())!=ComputeVersionTypeEnum.REPORT) {
//            return CommonResultEnum.PERMISSION_DENY;
//        }
//        ComputeVersionDTO versionDTO = parseVersionVO2DTO(entity);
//        if(dto.isPass()) {
//            versionDTO.setType(ComputeVersionTypeEnum.FINAL.getId());
//            projectInfo.setState(ProjectStateEnum.COMPLETE.getId());
//        } else {
//            versionDTO.setType(ComputeVersionTypeEnum.BACK.getId());
//            projectInfo.setState(ProjectStateEnum.REPORT.getId());
//        }
//        computeVersionService.update(versionDTO);
//        projectInfoDAO.updateById(projectInfo);
//        return CommonResultEnum.SUCCESS;
//    }
//
//    protected ComputeVersionDTO parseVersionVO2DTO(ComputeVersionVO vo) {
//        if(vo == null) {
//            return null;
//        }
//        ComputeVersionDTO dto = JSON.parseObject(JSON.toJSONString(vo),ComputeVersionDTO.class);
//        return dto;
//    }
//
//
//}
